package com.lgj.dao;

import com.lgj.domain.Student;
import com.lgj.utils.JDBCUtils;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

public class StudentDaoImpl implements StudentDao{

    @Override
    public ArrayList<Student> findAll() {
//        Connection connection = JDBCUtils.connection();
//        try {
//            Class.forName("com.mysql.cj.jdbc.Driver");
//        } catch (ClassNotFoundException e) {
//            e.printStackTrace();
//        }
        Statement statement = JDBCUtils.connection();
        String findAllSql = "select * from user";
        ArrayList<Student> students = new ArrayList<>();
        try {
            ResultSet result = statement.executeQuery(findAllSql);
            while(result.next()){
                Student student = new Student();
                student.setAge(result.getInt("age"));
                student.setHeight(result.getDouble("height"));
                student.setName(result.getString("name"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return students;
    }

    @Override
    public Student findById(int id) {
        return null;
    }

    @Override
    public int updateOne(Student student) {
        return 0;
    }

    @Override
    public int updateMany(ArrayList<Student> students) {
        return 0;
    }

    @Override
    public int deleteOne(int id) {
        return 0;
    }

    @Override
    public int deleteMany(ArrayList<Integer> ids) {
        return 0;
    }
}
